package com.example.demo.practice;

public class Test_quick {


//    public int[] sortArray(int[] nums) {
//
//        int [] arr = {3,1,5,6,9,12,4};
//    }

    public static void main(String[] args) {
        int [] arr = {5,1,1,2,0,0};
        quicKSort(arr, 0, arr.length-1);
        for(int i =0; i<arr.length;i++){
            System.out.println(arr[i]);
        }
    }


    public static void quicKSort(int[] nums, int i, int j){

        int start = i;
        int end = j;
        if(i >= j){
            return;
        }

        int a = nums[i];

        while(i < j){

            while(nums[j] > a && i < j){
                j--;
            }
            if(i >= j) break;
            nums[i] = nums[j];
            i++;

            while(nums[i] < a && i < j){
                i++;
            }
            if(i >= j) break;
            nums[j] =nums[i];
            j--;
        }
        nums[i] = a;
        quicKSort(nums, start, i-1);
        quicKSort(nums, i+1, end);
    }


}
